<?php 
$Items = $this->Items;

$linkDelete = $this->url(array('action'=>'delete','type'=>'multy'));
?>
<script type="text/javascript">
	function loadPage(x,url){
		var div_name = 'div#status' + x;
		//$(div_name).html('');
		$(div_name).load(url);
	}
</script>
<div class="content-box">
			<div class="box-body">
				<div class="box-header clear">
					<h2>Product Manager</h2>
				</div>
				
				<div class="box-wrap clear">
					
					<!-- DATA-TABLE JS PLUGIN -->
					<div id="data-table">
						<form name="appForm" id="appForm" method="post" action="<? echo $linkDelete;?>">
						
						<table class="style1 datatable">
						<caption valign="middle">List of Product									
							<span style="float: right;">
								<?php $lnkAdd = $this->url(array('module'=>'admin','controller'=>'product','action'=>'add'));?>
								<button class="button red small" type="button" onclick="toSite('<?php echo $lnkAdd;?>')">Add</button>
							</span>
						</caption>
						<thead>
							<tr>
								<th class="bSortable"><input type="checkbox" class="checkbox select-all" /></th>
								<th>Name</th>
								<th align="center">Picture</th>
								<th align="center">Status</th>
								<th align="center">Giá</th>
								<th align="center">Giảm giá</th>
								<th align="center">Số lần xem</th>
								<th align="center">Bảo hành</th>
								<th align="center">Action</th>
								<th align="center">CatName</th>
							</tr>
						</thead>
						<tbody>
						<?php 
							if(count($this->Items)>0){
								foreach ($this->Items as $key => $val){
									$id 		= $val['id'];
									$name 		= $val['name'];
									$price 		= $val['price'];
									$selloff 	= $val['selloff'];
									$hits 		= $val['hits'];
									$warranty 	= $val['warranty'];
									$cat_name 	= $val['CateName'];
									
									$lnkImg = PUBLIC_URL . '/img/product/';
									$picture = '<img src="'. $lnkImg . $val['picture'] .'" width="111"/>';
									
									
									$status = '<div id="status'.$id.'">';
									
									$lnkStatus = $this->url(array('module'=>'admin','controller'=>'product',
																	'action'=>'status','id'=>$val['id'],'status'=>$val['status']));
									if($val['status'] == 1){
										$status .= '<span class="pointer" onclick=loadPage("' . $val['id'] . '","'. $lnkStatus .'") ><img src="images/active.png"></span>';
									}else{
										$status .= '<span class="pointer" onclick=loadPage("' . $val['id'] . '","'. $lnkStatus .'") ><img src="images/inactive.png"></span>';
									}
									$status .= '</div>';
									
									$order 		= $val['order'];							
									
									$lnkEdit = $this->url(array('module'=>'admin','controller'=>'product','action'=>'edit','id'=>$val['id']))
							?>
							<tr>
								<td><input type="checkbox" class="checkbox" name="cid[]" id="cid[]" value="<?php echo $val['id'];?>"/></td>
								<td><?php echo $name;?></td>
								<td><?php echo $picture;?></td>
								<td><?php echo $status;?></td>
								<td><?php echo number_format($price,0,".",".");?></td>
								<td><?php echo number_format($selloff,0,".",".");?></td>
								<td><?php echo $hits;?></td>
								<td><?php echo $warranty;?></td>								
								<td>
									<a href="<?php echo $lnkEdit;?>"><img src="images/ico_settings_16.png" class="fl-space" alt=""></a>
											<a href="#delete<?php echo $id;?>" class="modal-link"><img src="images/ico_delete_16.png" class="fl" alt=""></a>
								</td>
								<td><?php echo $cat_name;?></td>	
							</tr>
							<div id="delete<?php echo $id;?>" class="modal-window modal-400">
											<p></p>
											<?php $url = $this->url(array('module'=>'admin','controller'=>'product','action'=>'delete','id'=>$id));?>
											<h2>Warning...!!!!!!!</h2>
											<p>Bạn có chắc chắc muốn <b>xóa</b> sản phẩm này không ???</p>
											<p>Lưu ý : Khi bạn xóa 1 sản phẩm thì tất cả hình ảnh của sản phẩm đó đều bị xóa.Cẩn thận !!!</p>
											<p>Lời khuyên : Bạn không nên xóa mà chỉ cần làm ẩn sản phẩm mình muốn xóa thôi !!!</p>
											<button class="green small" type="button" onclick="toSite('<?php echo $url;?>')">Đồng ý xóa</button>
							</div>
							
							<?php 
								}
							}
                            ?>
						</tbody>
						</table>						
						<div class="tab-footer clear fl">
							<div class="fl">
								<select name="dropdown" class="fl-space">
									<option value="none">choose action...</option>
									<option value="delete">Delete</option>
								</select>
								<input type="submit" value="Apply" id="submit1" class="button fl-space" />
							</div>
						</div>
						</form>
					</div><!-- /#table -->
				</div><!-- end of box-wrap -->
			</div> <!-- end of box-body -->
			</div> <!-- end of content-box -->